package com.hq.door.dao.impl;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Repository;

import com.hq.door.dao.IParentDao;
import com.hq.door.dto.Parent;
import com.hq.door.pojo.TParent;

/**
 * 作者：袁健宝
 * 日期：2016年12月31日 上午4:20:56
 */
@Repository("parentDao")
public class ParentDaoImpl extends BaseDaoImpl<TParent> implements IParentDao {

	@Override
	public TParent check(final String hql,final Object... conditions) {
		@SuppressWarnings("unchecked")
		TParent tparent = this.getHibernateTemplate().execute(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session session) throws HibernateException {
				Query query = session.createQuery(hql);				
				for(int i=0;i<conditions.length;i++){
					query.setParameter(i, conditions[i]);
				}
				return query.uniqueResult();
			}
		});
		return tparent;
	}

}
